package com.infocollect.project.api.ui;

import com.infocollect.project.api.entity.TappComControlEntity;
import com.infocollect.project.api.req.ComControlPage;
import com.infocollect.project.api.service.ITappComControlService;
import com.infocollect.project.form.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘亚平
 * @since 2021-06-23
 */
@Slf4j
@Api(value="TappComControlController",tags = "用户常用接口")
@RestController
@RequestMapping("/tappcomcontrol")
public class TappComControlController {
    @Autowired
    private ITappComControlService ITappComControlServiceApi;

    @ApiOperation("查询单个TappComControlEntity")
    @PostMapping("/selectById")
    public R<TappComControlEntity> selectById(@RequestParam("id") Long id) {
            return R.newOk(ITappComControlServiceApi.getById(id));
    }
    @ApiOperation("通过主键ID进行删除")
    @PostMapping("/deleteById")
    public R deleteById(@RequestParam("id") Long id) {
        if(ITappComControlServiceApi.deleteById(id)){
              return R.newOk();
             //return R.newOk();
        }else{
                return R.newError("删除失败！");
              // return R.newError("删除失败！");
        }
    }

    @ApiOperation("添加通用组件入库")
    @PostMapping("/addcomcontrol")
    public R addComControlInfo(@RequestBody TappComControlEntity req){
       if(ITappComControlServiceApi.addComControlInfo(req)){
           return R.newOk();
       }else{
           return R.newError("添加通用组件入库失败！");
       }
    }

    @ApiOperation("查询控件功能")
    @PostMapping("/querycomcontrollist")
    public R<List<TappComControlEntity>> queryComControlList(@RequestBody ComControlPage page) {
        return R.newOk(ITappComControlServiceApi.queryComControlList(page));
    }
}